package com.gitee.minimalismstyle.fresh.sys.api.validate

import com.gitee.minimalismstyle.fresh.common.core.validate.ValidateResult
import com.gitee.minimalismstyle.fresh.common.core.validate.ValueValidate
import com.gitee.minimalismstyle.fresh.sys.api.model.SysRole
import com.gitee.minimalismstyle.fresh.sys.api.service.SysRoleService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component

@Component
class RoleUniqueValueValidate(): ValueValidate {

    @Autowired
    lateinit var sysRoleService: SysRoleService

    override fun check(value: Any?, params: String?): ValidateResult {
        val roleDto = SysRole()
        roleDto.code = value.toString()
        return if(sysRoleService.isUnique(roleDto).get(false)){
            ValidateResult(true)
        }else{
            ValidateResult(false, "${value}角色代码已存在")
        }

    }
}